#服务端
import socket
import traceback
import threading
def talk(s,addr):
    print("本次连接的地址信息：", addr)
    try:
        while True:
            msg = s.recv(2048).decode("utf-8")
            print(addr, ",发来了信息：", msg)
            s.sendall(("你的折子【" + str(msg) + "】，朕知道了").encode("utf-8"))
            if msg == "exit":
                break
    except Exception as e:
        traceback.print_exc()
        print(addr,"断开了。异常信息如上！", sep="")
    finally:
        if s:
            s.close()
if __name__ == '__main__':
    st=socket.socket()
    st.bind(("192.168.100.85",9999))
    st.listen(10)
    while True:
        s,addr=st.accept()
        #启动一个线程，为这次连接服务
        th=threading.Thread(target=talk,args=(s,addr))
        th.start()